/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-06-09     WangJing       the first version
 */
#include "led.h"

static LED_Port_t LED_Port[LED_NUM] = {
        {GPIOC,GPIO_PIN_0},
};

void led_init(void){

    GPIO_InitTypeDef GPIO_InitStruct = {0};

    for(int i=0;i<LED_NUM;i++){

        switch((uint32_t)&LED_Port[i].gpioPort){

            case GPIOA_BASE: __HAL_RCC_GPIOA_CLK_ENABLE(); break;
            case GPIOB_BASE: __HAL_RCC_GPIOB_CLK_ENABLE(); break;
            case GPIOC_BASE: __HAL_RCC_GPIOC_CLK_ENABLE(); break;
            case GPIOD_BASE: __HAL_RCC_GPIOD_CLK_ENABLE(); break;
            case GPIOE_BASE: __HAL_RCC_GPIOE_CLK_ENABLE(); break;
            case GPIOF_BASE: __HAL_RCC_GPIOF_CLK_ENABLE(); break;
            case GPIOG_BASE: __HAL_RCC_GPIOG_CLK_ENABLE(); break;
            case GPIOH_BASE: __HAL_RCC_GPIOH_CLK_ENABLE(); break;
            case GPIOI_BASE: __HAL_RCC_GPIOI_CLK_ENABLE(); break;
            default: break;

        }

        HAL_GPIO_WritePin(LED_Port[i].gpioPort, LED_Port[i].gpioPin, GPIO_PIN_SET);

        GPIO_InitStruct.Pin = LED_Port[i].gpioPin;
        GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
        GPIO_InitStruct.Pull = GPIO_PULLUP;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
        HAL_GPIO_Init(LED_Port[i].gpioPort, &GPIO_InitStruct);
    }
}

void led_set(uint32_t led,uint8_t state){

    HAL_GPIO_WritePin(LED_Port[led].gpioPort, LED_Port[led].gpioPin, (GPIO_PinState)state);

}

